package lego.jbv;

import lejos.nxt.Button;
import lejos.nxt.ButtonListener;
import lejos.nxt.LCD;
import lejos.util.Delay;

public class main {
	public static BTController com;
	
	public static void main(String[] args) 
	{	
		int testPowerValue = 0;
		
		init();
		
		com = new BTController();
		com.start();
		
		LCD.drawString("GO GO GO", 0, 0);
		Button.ENTER.waitForPressAndRelease();
		LCD.clear();
		Delay.msDelay(200);

		com.setStartTime(System.currentTimeMillis());

		while(!Button.ESCAPE.isDown())
		{
			testPowerValue = com.getLeftPower(); 
			
			if(testPowerValue != 404 && testPowerValue != 300)
				Car.drive(com.getLeftPower(), com.getRightPower());
			
			else if(testPowerValue == 300)
			{
				Car.stop();
				LCD.drawString("GO GO GO", 0, 0);
				Button.ENTER.waitForPressAndRelease();
				LCD.clear();
				Delay.msDelay(200);
				com.setStartTime(System.currentTimeMillis());
				com.setPower(-100, -100);
			}
			
			else
				Delay.msDelay(1000);
		}
	}
	
	private static void init() {
		Button.ESCAPE.addButtonListener(new ButtonListener() {

			@Override
			public void buttonReleased(Button b) {
				LCD.clear();
				System.exit(0);
			}

			@Override
			public void buttonPressed(Button b) {
				// TODO Auto-generated method stub

			}
		});
	}

}
